package com.gaoda.booksystem.sysService.impl;

import com.gaoda.booksystem.entity.Book;
import com.gaoda.booksystem.entity.User;
import com.gaoda.booksystem.mapper.SysUserMapper;
import com.gaoda.booksystem.sysService.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    SysUserMapper sysUserMapper;

    //通过ID查询用户
    @Override
    public User findUserById(int id) {
        return sysUserMapper.findUserById(id);
    }

    //逻辑删除 + 分页
    @Override
    public List<User> queryUsers(String name, String userSex, String userDep, String userState, int currentPage, int pageCount) {
        return sysUserMapper.queryUsers(name, userSex, userDep, userState, (currentPage - 1) * pageCount, pageCount*currentPage);
    }

    //获得总页数
    @Override
    public int getTotalPage(int pageCount, String name, String userSex, String userDep, String userState) {
        Integer total = sysUserMapper.getTotalPage(name, userSex, userDep, userState);
        return (total - 1) / pageCount + 1;
    }

    //删除用户
    @Override
    public int deleteUserById(int id) {
        return sysUserMapper.deleteUserById(id);
    }

    //启用用户
    @Override
    public int updateUser(User user) {
        return sysUserMapper.updateUser(user);
    }

    //禁用用户
    @Override
    public int modifyUser(User user) {
        return sysUserMapper.modifyUser(user);
    }

    //修改用户信息
    @Override
    public int updateUserById(User user) {
        return sysUserMapper.updateUserById(user);
    }

    @Override
    public List<User> userList() {
        return sysUserMapper.userList();
    }

}
